﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PotentialRentals.Models;
using PotentialRentals.DAL;
using PotentialRentals.Repositories;

namespace PotentialRentals.Controllers
{
    public class HomeController : Controller
    {
        private UnitOfWork _context = new UnitOfWork(null);

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            var rentals = _context.RentalRepo.GetAll();

            return View(rentals);
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Create()
        {
            var rental = new Rental();

            ViewBag.RentalTypes = new SelectList(_context.RentalTypes, "RentTypeId", "Name");

            return View(rental);
        }

        /*
        [HttpPost]
        public ActionResult Create(Rental rental)
        {
            try
            {
                var user = new User() { UserId = 1, UserName = "brodkil" };
                rental.Type = new RentType() { RentTypeId = 1, Name = "Apartment", Description = "Apartment" };
                rental.Address.State = new State() { StateId = 1, Name = "NE" };
                rental.UserRank = new UserRentalRank() { RentalId = rental.RentalId, User = user };
                rental.Amenities = new List<RentalAmenity>() {
                    new RentalAmenity() { AmenityId = 1, Name = "Laundry", Description = "Laundry" },
                    new RentalAmenity() { AmenityId = 2, Name = "Dishwasher", Description = "Dishwasher" }
                };
                rental.Address.Amenities = new List<AddressAmenity>() {
                    new AddressAmenity() { AmenityId = 1, Name = "Laundry Facilities", Description = "Laundry Facilities" },
                    new AddressAmenity() { AmenityId = 2, Name = "Clubhouse", Description = "Clubhouse" }
                };

                _context.RentalRepo.Add(rental);
                _context.Save();

                return RedirectToAction("Index");
            }
            catch
            {
                return View(rental);
            }
        }
        */
    }
}
